var apiUrl = 'https://landing.zibojinchi.com/api'

var baseUrl = '';
if (process.env.NODE_ENV === 'development') {
	baseUrl = 'https://landing.zibojinchi.com/api'
} else {
	baseUrl = apiUrl
}
const request = (url = '', date = {}, type = 'post', header = {}) => {
	var token = uni.getStorageSync('token') || '';
	return new Promise((resolve, reject) => {
		uni.request({
			method: type,
			url: baseUrl + url,
			data: date,
			header: {
				"Authorization": token,
				"Platform": '2'
			},
		}).then((res) => {
			resolve(res.data);

			if (res.data.code == 401) {
				uni.removeStorageSync('token');
				uni.removeStorageSync('userInfo');
				setTimeout(() => {
					uni.navigateTo({
						url: '/pages/login/login'
					})
				}, 1500)
			}
		}).catch(error => {
			console.log('出错了', error)
			reject(error);
		})
	})
}

export default request